package com.itlong.cloud.sdk.resource;

import com.itlong.cloud.POJO.DTO.sdk.*;
import com.itlong.cloud.POJO.DTO.sdk.jd.JDPassRecordDTO;
import com.itlong.cloud.POJO.PO.DeviceElevatorFloorConfigPO;
import com.itlong.cloud.POJO.PO.DeviceElevatorInfoPO;
import com.itlong.cloud.POJO.VO.jd.JDResultVO;
import com.itlong.cloud.POJO.VO.sdk.CloudElevatorSDKGetByDeviceUniqueVO;
import com.itlong.cloud.POJO.VO.sdk.RobotNoninductiveDeviceUniqueVO;
import com.itlong.cloud.POJO.VO.sdk.RobotNoninductiveHistoryRecordVO;
import com.itlong.cloud.POJO.VO.sdk.SDKDeviceCloudControllerInfoVO;
import com.itlong.cloud.equip.sdk.ICloudElevatorSDKServerCloudServiceClient;
import com.itlong.cloud.sdk.service.ICloudElevatorSDKServerCloudService;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;


/**
 * <desc>
 *      云电梯SDK设备服务暴露接口实现类
 * <desc/>
 *
 * @createDate 2018/12/27
 */
@RestController
public class CloudElevatorSDKServerCloudServiceResource implements ICloudElevatorSDKServerCloudServiceClient {

    @Autowired
    private ICloudElevatorSDKServerCloudService iCloudElevatorSDKServerCloudService;

    /**
     * <desc>
     *      查询项目下电梯设备唯一码列表
     * </desc>
     *
     * @param cloudElevatorSDKServerGetElevatorPageDTO 云电梯SDK查询项目下电梯设备唯一码列表DTO
     * @return 云电梯SDK查询项目下电梯设备唯一码列表VO
     * @author wangzhi
     * @createDate 2018/12/27
     */
    @Override
    @PostMapping(path = "/cloudElevatorSDK/server/getElevatorPage")
    public List<String> getElevatorPage(@RequestBody CloudElevatorSDKServerGetElevatorPageDTO cloudElevatorSDKServerGetElevatorPageDTO) throws Exception {
        return iCloudElevatorSDKServerCloudService.getElevatorPage(cloudElevatorSDKServerGetElevatorPageDTO);
    }

    /**
     * <desc>
     *      根据设备唯一码查询电梯信息
     * </desc>
     *
     * @param cloudElevatorSDKGetByDeviceUniqueDTO
     * @return 根据设备唯一码查询电梯信息VO
     * @author wangzhi
     * @createDate 2018/12/28
     */
    @Override
    @PostMapping(path = "/cloudElevatorSDK/server/getElevatorInfo")
    public List<CloudElevatorSDKGetByDeviceUniqueVO> getElevatorInfo(@RequestBody CloudElevatorSDKGetByDeviceUniqueDTO cloudElevatorSDKGetByDeviceUniqueDTO) throws Exception {
        return iCloudElevatorSDKServerCloudService.getElevatorInfo(cloudElevatorSDKGetByDeviceUniqueDTO);
    }

    /**
     * <desc>
     *      根据设备唯一码查询电梯信息
     * </desc>
     *
     * @param cloudElevatorSDKGetByDeviceUniqueDTO
     * @return 根据设备唯一码查询电梯信息VO
     * @author wangzhi
     * @createDate 2018/12/28
     */
    @Override
    @PostMapping(path = "/cloudElevatorSDK/server/getElevatorInfoForRobot")
    public List<RobotNoninductiveDeviceUniqueVO> getElevatorInfoForRobot(@RequestBody CloudElevatorSDKGetByDeviceUniqueDTO cloudElevatorSDKGetByDeviceUniqueDTO) throws Exception {
        return iCloudElevatorSDKServerCloudService.getElevatorInfoForRobot(cloudElevatorSDKGetByDeviceUniqueDTO);
    }

    /**
     * <desc>
     *      发送开门关门指令
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author Juguang.S
     * @createDate 2018/12/28
     */
    @Override
    @PostMapping(path = "/cloudElevatorSDK/server/sendOpenAndCloseDoor")
    public void sendOpenAndCloseDoor(@RequestBody CloudElevatorSDKServerSendCommandDTO cloudElevatorSDKServerSendCommandDTO) throws Exception {
        iCloudElevatorSDKServerCloudService.sendOpenAndCloseDoor(cloudElevatorSDKServerSendCommandDTO);
    }

    /**
     * <desc>
     *      根据楼层名称获取真实楼层
     * </desc>
     *
     * @param goFloor
     * @param fromFloor
     * @return
     * @author Jiaqi.X
     * @createDate 2018/01/03
     */
    @Override
    @RequestMapping(path = "smartCommunity/interface/elevator/getFloorNumByLogicFloor")
    public Map<String,Object> getFloorNumByLogicFloor(@RequestParam("goFloor") String goFloor,
                                               @RequestParam("fromFloor") String fromFloor,
                                               @RequestParam("deviceUnique") String deviceUnique){
        return iCloudElevatorSDKServerCloudService.getFloorNumByLogicFloor(goFloor,fromFloor,deviceUnique);
    }

    /**
     * <desc>
     *      获取上报的信息
     * </desc>
     *
     * @param appId
     * @param appSecret
     * @param projectId
     * @return
     * @author Jiaqi.X
     * @createDate 2019/01/22
     */
    @Override
    @RequestMapping(path = "cloudElevatorSDK/interface/elevator/getReportInfo")
    public Map<String,Object> getReportInfo(@RequestParam("appId") String appId,@RequestParam("appSecret")  String appSecret,@RequestParam("projectId") String projectId){
        return iCloudElevatorSDKServerCloudService.getReportInfo(appId,appSecret,projectId);
    }

    /**
     * <desc>
     *      打开关闭上报状态
     * </desc>
     *
     * @param cloudElevatorSDKStateReportDTO
     * @author jiaqi.X
     * @createDate 2019/01/03
     */
    @Override
    @RequestMapping(path = "cloudElevatorSDK/interface/elevator/setOpenOrCloseStateReport")
    public void setOpenOrCloseStateReport(@RequestBody CloudElevatorSDKStateReportDTO cloudElevatorSDKStateReportDTO) throws IOException {
        iCloudElevatorSDKServerCloudService.setOpenOrCloseStateReport(cloudElevatorSDKStateReportDTO);
    }

    /**
     * <desc>
     *      根据楼层名称获取实际楼层和权限标识
     * </desc>
     *
     * @param floors
     * @param deviceUnique
     * @return
     * @author Jiaqi.X
     * @createDate 2019/08/15
     */
    @Override
    @RequestMapping(path = "smartCommunity/interface/elevator/getFloorNumAndNaturalFloorByLogicFloor")
    public Map<String, Object> getFloorNumAndNaturalFloorByLogicFloor(@RequestParam("floors") String floors, @RequestParam("deviceUnique") String deviceUnique) {
        return iCloudElevatorSDKServerCloudService.getFloorNumAndNaturalFloorByLogicFloor(floors, deviceUnique);
    }

    /**
     * <desc>
     *      查询群控器的呼梯结果
     * </desc>
     *
     * @param robotId
     * @param deviceUnique
     * @return
     * @author Jiaqi.X
     * @createDate 2019/07/17
     */
    @Override
    @RequestMapping(path = "cloudElevatorSDK/interface/elevator/getCallInfo")
    public String getCallInfo(@RequestParam("robotId") String robotId,@RequestParam("deviceUnique") String deviceUnique) throws IOException {
        return iCloudElevatorSDKServerCloudService.getCallInfo(robotId,deviceUnique);
    }

    /**
     * <desc>
     *      查询群控器所绑定的设备
     * </desc>
     *
     * @param controllerDeviceUnique
     * @return
     * @author Jiaqi.X
     * @createDate 2019/07/24
     */
    @Override
    @RequestMapping(path = "cloudElevatorSDK/interface/elevator/getDeviceUniqueByControllerDeviceUnique")
    public String getDeviceUniqueByControllerDeviceUnique(@RequestParam("controllerDeviceUnique") String controllerDeviceUnique){
        return iCloudElevatorSDKServerCloudService.getDeviceUniqueByControllerDeviceUnique(controllerDeviceUnique);
    }

    /**
     *      获取项目下机器人的呼梯记录
     * </desc>
     *
     * @param dto
     * @return
     * @author Jiaqi.X
     * @createDate 2019/07/24
     */
    @Override
    @RequestMapping(path = "cloudElevatorSDK/interface/elevator/getHistoryRecords")
    public Page<RobotNoninductiveHistoryRecordVO> getHistoryRecords(@RequestBody RobotNoninductiveHistoryRecordDTO dto) throws Exception{
        return iCloudElevatorSDKServerCloudService.getHistoryRecords(dto);
    }

    /**
     * <desc>
     *      获取云电梯信息
     * </desc>
     *
     * @param deviceUnique
     * @return
     * @author Qiang.S
     * @createDate 2020/04/08
     */
    @Override
    @RequestMapping(path = "cloudElevatorSDK/interface/elevator/getElevatorByDeviceUnique")
    public DeviceElevatorInfoPO getElevatorByDeviceUnique(@RequestParam("deviceUnique") String deviceUnique) throws Exception{
        return iCloudElevatorSDKServerCloudService.getElevatorByDeviceUnique(deviceUnique);
    }


    /**
     * <desc>
     *      根据jd设备号获取云电梯信息
     * </desc>
     *
     * @param jdDeviceUnique
     * @return
     * @author caoshuai
     * @createDate 2020/08/03
     */
    @Override
    @RequestMapping(path = "cloudElevatorSDK/interface/elevator/getElevatorByJDDeviceUnique")
    public DeviceElevatorInfoPO getElevatorByJDDeviceUnique(@RequestParam("deviceId") String jdDeviceUnique) {
        return iCloudElevatorSDKServerCloudService.getElevatorByJDDeviceUnique(jdDeviceUnique);
    }

    /**
     * <desc>
     *      获取楼层信息
     * </desc>
     *
     * @param params
     * @return
     * @author caoshuai
     * @createDate 2020/08/05
     */
    @Override
    @RequestMapping(path = "cloudElevatorSDK/interface/elevator/getFloorInfoByMap")
    public List<DeviceElevatorFloorConfigPO> getFloorInfoByMap(@RequestBody Map<String, Object> params) {

        return iCloudElevatorSDKServerCloudService.getFloorInfoByMap(params);
    }

    /**
     * <desc>
     * JD打开关闭上报状态
     * </desc>
     *
     * @param deviceUnique
     * @return
     * @author caoshuai
     * @createDate 2020/08/10
     */
    @Override
    @RequestMapping(path = "cloudElevatorSDK/interface/elevator/jdOpenOrCloseStateReport")
    public JDResultVO jdOpenOrCloseStateReport(@RequestParam("deviceUnique") String deviceUnique,
                                               @RequestParam ("openOrClose") String openOrClose,
                                               @RequestParam ("deviceId") String deviceId,
                                               @RequestParam ("appid") String appid,
                                               @RequestParam ("secret") String secret) {
        return iCloudElevatorSDKServerCloudService.jdOpenOrCloseStateReport(deviceUnique, openOrClose, deviceId, appid, secret);
    }

    /**
     * <desc>
     *      获取云控制器信息
     * </desc>
     *
     * @param deviceUnique
     * @return
     * @author caoshuai
     * @createDate 2020/08/05
     */
    @Override
    @RequestMapping(path = "cloudElevatorSDK/interface/elevator/getDeviceCloudControllerInfo")
    public SDKDeviceCloudControllerInfoVO getDeviceCloudControllerInfo(@RequestParam("deviceUnique") String deviceUnique) {
        return iCloudElevatorSDKServerCloudService.getDeviceCloudControllerInfo(deviceUnique);
    }

    /**
     * <desc>
     *  查询华为云下群控器所绑定的设备
     * </desc>
     *
     * @param controllerDeviceUnique
     * @return
     * @author caoshuai
     * @createDate 2020/08/10
     */
    @Override
    @RequestMapping(path = "cloudElevatorSDK/interface/elevator/getDeviceUniqueBy")
    public String getDeviceUniqueBy(@RequestParam("controllerDeviceUnique") String controllerDeviceUnique) {
        return iCloudElevatorSDKServerCloudService.getDeviceUniqueBy(controllerDeviceUnique);
    }

    /**
     * <desc>
     *      京东上报通行记录
     * </desc>
     *
     * @param jdPassRecordDTO 京东通行记录VO
     * @return
     * @Author Zhu.yj
     * @createDate  2021/1/11
     */
    @Override
    @PostMapping("/jd/eventReport/reportPassRecord")
    public void reportPassRecord(@RequestBody JDPassRecordDTO jdPassRecordDTO) throws Exception {
        iCloudElevatorSDKServerCloudService.reportPassRecord(jdPassRecordDTO);
    }

}
